// pages/homepage/homepage.js
var Session = getApp().globalData.header
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CoverNovels: [],
    HotNovel: [],
    NovelType:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: 'https://www.dmx007.com/BaseData',
      method: 'POST',
      data: { PitctureNum: 4 },
      header: Session,
      success: function (res) {
        
        console.log(res.data.Cover)
        that.setData({
          CoverNovels: res.data.Cover,
          HotNovel: res.data.HotNovel,
          NovelType: res.data.TypeNovels
        })
        wx.hideLoading()
      },
      fail: function (res) {
        wx.hideLoading()
        wx.showToast({
          title: '连接服务器失败',
          icon: 'none',
          duration: 2000
        })
      },
      complete: function (res) {
        if (res.statusCode == 502) {
          wx.showToast({
            title: '连接服务器失败502',
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  
  goToDetail: function (event) {
    wx.navigateTo({
      url: './/pages/Detail/Detail?Object=' + JSON.stringify(event.currentTarget.dataset.novel),
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: 'https://www.dmx007.com/BaseData',
      method: 'POST',
      data: { PitctureNum: 4 },
      header: Session,
      success: function (res) {
        wx.hideLoading()
        that.setData({
          CoverNovels: res.data.Cover,
          HotNovel: res.data.HotNovel,
          NovelType: res.data.TypeNovels
        })
      },
      fail: function (res) {
        wx.hideLoading()
        wx.showToast({
          title: '连接服务器失败',
          icon: 'none',
          duration: 2000
        })
      },
      complete: function (res) {
        if (res.statusCode == 502) {
          wx.showToast({
            title: '连接服务器失败502',
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})